// import { getApiResolveRegionsListApi } from '@/apis/modules/resolve/area'
// import { getApiSiteSiteGroupListApi } from '@/apis/modules/site/siteGroup'
// import {
//   getComputeMachineGroupListApi,
// } from '@/apis/modules/group.ts'

import { getCdnGroupListApi } from '@/apis/modules/cdn.ts'

interface RegionHookOps {
  immediate: boolean
}
export default function useGroupArea(
  type: 'region' | 'site_group' | 'all' = 'all',
  opts: RegionHookOps = { immediate: true },
) {
  const areaListOptions = ref<LabelValue[]>([])
  const siteGroupOptions = ref<LabelValue[]>([])
  const getRegion = () => {
    getCdnGroupListApi({}).then((res) => {
      areaListOptions.value = (res.list ?? []).map(item => ({
        label: item.name ?? '',
        value: item.id ?? '',
      }))
    })
  }
  const getSiteGroup = () => {
    getCdnGroupListApi({}).then((res) => {
      siteGroupOptions.value = (res.list ?? []).map(item => ({
        label: item.name ?? '',
        value: item.id ?? '',
      }))
      siteGroupOptions.value.unshift({ label: '默认', value: '-1' })
    })
  }

  const getOptions = () => {
    const map: Record<string, () => void> = {
      all: () => {
        getRegion()
        getSiteGroup()
      },
      region: getRegion,
      site_group: getSiteGroup,
    }
    map[type] && map[type]()
  }
  onMounted(() => {
    if (opts.immediate) {
      getOptions()
    }
  })
  return {
    areaListOptions,
    siteGroupOptions,
    getOptions,
    getRegion,
    getSiteGroup,
  }
}
